package com.lagou.rabbitmq.dao;

import com.lagou.rabbitmq.pojo.Good;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

public interface GoodDao extends JpaRepository<Good, Integer> {

    @Modifying
    @Query("update Good g set g.inventory = g.inventory - 1 where g.id = ?1 and g.inventory > 0")
    int inventorySubById(int id);

    @Modifying
    @Query("update Good g set g.inventory = g.inventory + 1 where g.id = ?1")
    int inventoryAddById(int id);

}
